<?php
  session_start();
  if ($_POST) {
    $retorno = $_POST["pageBack"];
    header("Location: $retorno");
    include("config/login-defs.php");
    $formAction = $_POST["formAction"];
    if ($formAction == "excluir") {
      $query = "UPDATE categoria SET status = 'Inativo' WHERE id_categoria = " . $_POST["keyValue"] ;	  
      $data = mysql_query($query) or print(mysql_error());
    } else if ($formAction == "alterar") {
      $id = $_POST["id"];
      $query = 'UPDATE categoria SET descricao = "' . $_POST["fldDescricao"] . '", 
		                             operacao = "' . $_POST["cbOperacao"] . '", 
									 status = "' . $_POST["cbStatus"] . '" ' .
                    'WHERE id_categoria = ' . $_POST["id"];
      $data = mysql_query($query) or print(mysql_error());
    } else if ($formAction == "inserir") {
      // SQL Insert CMS.
      $query = 'INSERT INTO categoria (descricao, operacao, status)' .
                  ' VALUES ("' . $_POST["fldDescricao"] . '","' 
				               . $_POST["cbOperacao"] .'","' 
						       . $_POST["cbStatus"] . '")';
      $data = mysql_query($query) or print(mysql_error());	  
    }
  }
?>